<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2022/3/21
 * Time: 15:56
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

namespace app\api\controller\v1;

use app\BaseController;
use app\common\lib\Show;
use app\common\lib\Status;
use EasyWeChat\Factory;
use think\App;

class Base extends BaseController
{
    protected $mini_app = null;
    protected $model = null;
    protected string $m_openid = "";
    public function __construct(App $app)
    {
        parent::__construct($app);
        $config = [
            "app_id"=>sysconfig('weixin',"wx_mini_app_id"),
            "secret"=>sysconfig('weixin','wx_mini_secret_id'),
            'response_type' => 'array',
            'log' => [
                'level' => 'debug',
                'file' => runtime_path('easywechat').'wechat.log',
            ],
        ];
        $this->mini_app = Factory::miniProgram($config);
        $this->m_openid = $this->request->openid ?? "";
    }

    /**
     * 获取列表
     * @return array|\think\response\Json
     */
    public function getBaseByListInfo(array $where = [],string $field = "*", string $orderBy = "id desc"){
        $limit = $this->request->param('limit',10,'intval');

        try {
            $lists = $this->model->getPaginateByNormalListInfo($where,$limit,$field,$orderBy);
        } catch (\Exception $exception) {
            return Show::json_show(Status::mini_error,$exception->getMessage());
        }
        return Show::json_show(Status::mini_normal,"ok",$lists);
    }
}